#include "stdafx.h"
#include "EntityManager.h"


EntityManager::EntityManager(bool bLoad /* = true */)
:m_bLoad(bLoad)
{
}

IEntity*	EntityManager::getEntity(int nID)
{
	EntityMap::iterator it = m_theEntities.find(nID);
	if (m_theEntities.end()==it)
	{
		return NULL;
	}
	else
	{
		return it->second;
	}
}

bool
EntityManager::addEntity(int nID, IEntity* e)
{
	if (getEntity(nID) || e==NULL)
	{
		return false;
	}

	m_theEntities[nID] = e;
	e->setID(nID);
	if (m_bLoad)
	{
		e->onLoad();
	}
	return true;
}

bool
EntityManager::addEntity(int nID, IEntityBuilder* b)
{
	IEntity* pEtt = b->build();
	if (pEtt)
		return addEntity(nID, pEtt);
	else
		return false;
}

bool
EntityManager::rmvEntity(int nID, IEntity*& e)
{
	EntityMap::iterator it = m_theEntities.find(nID);
	if (m_theEntities.end()==it)
	{
		return false;
	}
	else
	{
		e = it->second;
		m_theEntities.erase(it);
		return true;
	}
}

void
EntityManager::forEach(IEntityVisitor& v)
{
	for (EntityMap::iterator it=m_theEntities.begin(); it!=m_theEntities.end(); it++)
	{
		it->second->accept(v);
	}
}


bool
EntityManager::addGene(IGene*)
{
	return true;
}

bool
EntityManager::addGene(IGeneCreateData *pDynamicData)
{
	return true;
}

bool
EntityManager::rmvGene(int nGrpID)
{
	return true;
}

bool
EntityManager::addRegEvt(int nEvtGrp, int nEvt, IGene* pGene)
{
	return true;
}

bool
EntityManager::rmvRegEvt(int nEvtGrp, int nEvt, IGene* pGene)
{
	return true;
}

bool
EntityManager::onEvent(IEvt& evt)
{
	return true;
}
